﻿using System;
using System.Data;
using dk2Repository.Example.DAL;
using dk2Repository.Interfaces;

namespace dk2Repository.Example.BL
{
    [Table("Users")]
    class User : UserData
    {
        public enum enumGender
        {
            Male, Female
        }

        [PrimaryKey(true)]
        [Column]
        public int Id { get; set; }

        [Column("Name", 100)]
        public string Name { get; set; }

        [Column("DateOfBirth", true)]
        public DateTime? DateOfBirth { get; set; }

        [Column]
        public enumGender Gender { get; set; }

        [Column]
        public int DepartmentId { get; set; }

        [Reference("DepartmentId", "Id", "d_")]
        public Department Department { get; set; }


        public string DepartmentName
        {
            get
            {
                return Department == null ? "?" : Department.Name;
            }
        }

    }

    internal class GenderConverter : IConverter
    {

        public object ConvertToEntityValue(object value)
        {
            var b = Convert.ToBoolean(value);
            return b ? User.enumGender.Female : User.enumGender.Male;
        }

        public object ConvertToDbValue(object value)
        {
            return ((User.enumGender)value) == User.enumGender.Female;
        }
    }
}
